package com.ysqcould.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.lang.Dict;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.system.domain.AssDict;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ysqcould.system.service.IDictService;

/**
 * 字典Controller
 * 
 * @author ruoyi
 * @date 2022-08-19
 */
@RestController
@RequestMapping("/system/Assdict")
public class DictController extends BaseController
{
    @Autowired
    private IDictService dictService;

    /**
     * 查询字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:Assdict:list')")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        startPage();
        AssDict dict=new AssDict();
        List<AssDict> list = dictService.selectDictList(dict);
        return getDataTable(list);
    }

    /**
     * 导出字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:Assdict:export')")
    @Log(title = "字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssDict dict)
    {
        List<AssDict> list = dictService.selectDictList(dict);
        ExcelUtil<AssDict> util = new ExcelUtil<AssDict>(AssDict.class);
        util.exportExcel(response, list, "字典数据");
    }

    /**
     * 获取字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:Assdict:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dictService.selectDictById(id));
    }

    /**
     * 新增字典
     */
    @PreAuthorize("@ss.hasPermi('system:Assdict:add')")
    @Log(title = "字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssDict dict)
    {
        return toAjax(dictService.insertDict(dict));
    }

    /**
     * 修改字典
     */
    @PreAuthorize("@ss.hasPermi('system:Assdict:edit')")
    @Log(title = "字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssDict dict)
    {
        return toAjax(dictService.updateDict(dict));
    }

    /**
     * 删除字典
     */
    @PreAuthorize("@ss.hasPermi('system:Assdict:remove')")
    @Log(title = "字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dictService.deleteDictByIds(ids));
    }
}
